package com.qezhhnjy.mall.member.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.member.MemberReceiveAddress;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.member.service.MemberReceiveAddressService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 会员收货地址 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "会员收货地址接口")
@Slf4j
@RequestMapping("/member-receive-address")
public class MemberReceiveAddressController {
    @Resource
    private MemberReceiveAddressService memberReceiveAddressService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取会员收货地址信息")
    public BaseResult<MemberReceiveAddress> get(Long id) {
        MemberReceiveAddress memberReceiveAddress = memberReceiveAddressService.getById(id);
        return BaseResult.success(memberReceiveAddress);
    }

    @PostMapping("/save")
    @Operation(summary = "新增会员收货地址信息")
    public BaseResult<MemberReceiveAddress> save(@RequestBody MemberReceiveAddress memberReceiveAddress) {
        memberReceiveAddressService.save(memberReceiveAddress);
        return BaseResult.success(memberReceiveAddress);
    }

    @PutMapping("/update")
    @Operation(summary = "更新会员收货地址信息")
    public BaseResult<MemberReceiveAddress> update(@RequestBody MemberReceiveAddress memberReceiveAddress) {
        memberReceiveAddressService.updateById(memberReceiveAddress);
        return BaseResult.success(memberReceiveAddress);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取会员收货地址信息")
    public BaseResult<Page<MemberReceiveAddress>> page(@RequestBody Page<MemberReceiveAddress> page) {
        memberReceiveAddressService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除会员收货地址信息")
    public BaseResult<Long> delete(Long id) {
        memberReceiveAddressService.removeById(id);
        return BaseResult.success(id);
    }
}

